package com.ruoyi.web.controller.system;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysForm;
import com.ruoyi.system.service.ISysFormService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 单Controller
 * 
 * @author ruoyi
 * @date 2025-08-31
 */
@RestController
@RequestMapping("/system/form")
public class SysFormController extends BaseController
{
    @Autowired
    private ISysFormService sysFormService;

    /**
     * 查询单列表
     */
    @PreAuthorize("@ss.hasPermi('system:form:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysForm sysForm)
    {
        startPage();
        List<SysForm> list = sysFormService.selectSysFormList(sysForm);
        return getDataTable(list);
    }

    /**
     * 导出单列表
     */
    @PreAuthorize("@ss.hasPermi('system:form:export')")
    @Log(title = "单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysForm sysForm)
    {
        List<SysForm> list = sysFormService.selectSysFormList(sysForm);
        ExcelUtil<SysForm> util = new ExcelUtil<SysForm>(SysForm.class);
        util.exportExcel(response, list, "单数据");
    }

    /**
     * 获取单详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:form:query')")
    @GetMapping(value = "/{formId}")
    public AjaxResult getInfo(@PathVariable("formId") Long formId)
    {
        return success(sysFormService.selectSysFormByFormId(formId));
    }

    /**
     * 新增单
     */
    @PreAuthorize("@ss.hasPermi('system:form:add')")
    @Log(title = "单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysForm sysForm)
    {
        return toAjax(sysFormService.insertSysForm(sysForm));
    }

    /**
     * 修改单
     */
    @PreAuthorize("@ss.hasPermi('system:form:edit')")
    @Log(title = "单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysForm sysForm)
    {
        return toAjax(sysFormService.updateSysForm(sysForm));
    }

    /**
     * 删除单
     */
    @PreAuthorize("@ss.hasPermi('system:form:remove')")
    @Log(title = "单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{formIds}")
    public AjaxResult remove(@PathVariable Long[] formIds)
    {
        return toAjax(sysFormService.deleteSysFormByFormIds(formIds));
    }

    @GetMapping("/list_select")
    public AjaxResult listSelect()
    {
        return sysFormService.listSelect();
    }
}
